package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.FlyPageQueryDTO;
import com.sky.entity.Fly;
import com.sky.vo.FlyVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface FlyMapper {

    /**
     * 根据id查询无人机
     * @param id
     * @return
     */
    @Select("select * from fly where id = #{id}")
    Fly getById(Long id);

    /**
     * 分页查询无人机
     * @param flyPageQueryDTO
     * @return
     */
    Page<FlyVO> pageQuery(FlyPageQueryDTO flyPageQueryDTO);

    /**
     * 更新无人机
     * @param fly
     */
    void update(Fly fly);

    /**
     * 新增无人机
     * @param fly
     */
    @Select("insert into fly (name, battery, status, create_time, update_time, create_user, update_user) " +
            "values (#{name}, #{battery}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void insert(Fly fly);

    /**
     * 删除无人机
     * @param id
     */
    @Select("delete from fly where id = #{id}")
    void delete(Long id);

    /**
     * 获取可用的无人机
     * @return
     */
    @Select("select * from fly where status = 1 order by create_time limit 1")
    Fly getAvailableFly();

    /**
     * 更新无人机电量
     * @param Id 无人机id
     * @param battery 电量
     */
    void updateBattery(Long Id, int battery);

}
